package com.yenlien.traceyun.milk.controller;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.business.entity.ProcessDetail;
import com.yenlien.traceyun.business.interceptor.UserAuthUtil;
import com.yenlien.traceyun.milk.service.ProcessDetailService;
import com.yenlien.traceyun.webase.controller.BaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * 加工详情
 *
 * @author maybe
 * @date 2020年7月28日
 */

@Api(tags = "加工详情")
@RestController
@RequestMapping("/processDetail")
public class ProcessDetailController extends BaseController {
    @Autowired
    private ProcessDetailService processDetailService;

    //分页查询列表
//	@DataAuth
    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody JSONObject params) {
        ProcessDetail processDetail = new ProcessDetail();
        processDetail.setPage(params.getIntValue("page"));
        processDetail.setProductName(params.getString("productName"));
        if (!StringUtils.isEmpty(params.getString("companyId"))) {
            processDetail.setCompanyId(params.getString("companyId"));
        } else {
            processDetail.setCompanyId(UserAuthUtil.getLoginUser().getCompanyId());
        }
        return buildPage(processDetailService.findByList(processDetail));
    }

    //单独绑定产品信息
    @RequestMapping(value = "/bindProductMsg/{id}/{productId}")
    public Object bindProduct(@PathVariable("id") String id, @PathVariable("productId") String productId) {
        processDetailService.bindProduct(id, productId);
        return success("success");
    }

    //根据ID查询详情
    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable("id") String id) {
        return success(processDetailService.findById(id));
    }
}
